package com.settlement.system.controller;

import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.RefundAuditReport;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.IRefundAuditReportService;
import com.settlement.system.common.util.common.FasUtil;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 退款稽核报表 前端控制器
 * @author xiaochuan
 * @since 2020-05-21
 */

@RestController
@RequestMapping("/refundAudit")
public class RefundAuditReportController extends ExcelController<RefundAuditReport> {

    @Resource
    private IRefundAuditReportService refundAuditReportService;

    @Override
    public IBaseService init() {
        return refundAuditReportService;
    }

    @Override
    public Class<?> getModelClass() {
        return RefundAuditReport.class;
    }


    @Override
    protected void setFootModel(Map<String, Object> result, Map<String, Object> model) throws ServiceException {
        try {
            result.put("foot",refundAuditReportService.selectFoot(model));
        } catch (ServiceException e) {
           throw new ServiceException(e);
        }
    }

    @Override
    protected void setParamsModel(Map<String, Object> model) {
        model.put("spOrderNo",model.get("refBillNo"));
        FasUtil.formatInQueryCondition(model,"refBillNo","threeLevelChannelNo","orderSourceNo");
        super.setParamsModel(model);
    }

    @Override
    protected List<RefundAuditReport> getExportDate(Map<String, Object> params) throws ServiceException {
        List<RefundAuditReport> tempList = new ArrayList<>();
        refundAuditReportService.getDataByHandler(params, new ResultHandler<RefundAuditReport>() {

            @Override
            public void handleResult(ResultContext<? extends RefundAuditReport> resultContext) {
                tempList.add(resultContext.getResultObject());
            }
        });
        return tempList;
    }
}

